package com.amikomgamedev.labirinhantu;

import org.andengine.opengl.view.RenderSurfaceView;
import org.andengine.ui.activity.BaseGameActivity;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;

public class AdMoob
{
    private String			ID = "a1504c944115cfb";

    private static BaseGameActivity	m_Activity;
    private static AdView	   	m_AdView;

    public AdMoob(Context p_Context)
    {
	m_Activity = (BaseGameActivity) p_Context;
    }

    public void destroyAds()
    {
	if (m_AdView != null)
	{
	    m_AdView.destroy();
	}
    }

    public void createAds()
    {
	AdRequest adRequest = new AdRequest();
//	adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
	m_AdView = new AdView(m_Activity, AdSize.BANNER, ID);
	m_AdView.refreshDrawableState();
	m_AdView.setVisibility(View.INVISIBLE);
	m_AdView.loadAd(adRequest);
    }

    public static void addAds(RenderSurfaceView mRenderSurfaceView)
    {
	FrameLayout frameLayout = new FrameLayout(m_Activity);

	LayoutParams frameLayoutLayoutParams = new LayoutParams(m_Activity
		.getWindowManager()
		.getDefaultDisplay()
		.getWidth(), m_Activity
		.getWindowManager()
		.getDefaultDisplay()
		.getHeight());

	LayoutParams m_AdViewLayoutParams = new LayoutParams(
		LayoutParams.WRAP_CONTENT,
		LayoutParams.WRAP_CONTENT,
		Gravity.CENTER_HORIZONTAL | Gravity.CENTER);

	mRenderSurfaceView.setRenderer(m_Activity.getEngine(), m_Activity);

	frameLayout.addView(mRenderSurfaceView, frameLayoutLayoutParams);
	frameLayout.addView(m_AdView, m_AdViewLayoutParams);

	m_Activity.setContentView(frameLayout);
    }

    public static void visibleAds()
    {
	m_AdView.setVisibility(View.VISIBLE);
    }
}
